macro winproc [args]			   ; define procedure
 { common
   match name params, args>
    \{
      define@proc name,<hwnd,wmsg,wparam,lparam>
    \}
 }


macro ondefault {  ; begins procedure instructions
  common
    local ..msgcounter, ..msglist
    msgcounter equ ..msgcounter
    msglist equ ..msglist

    ..msgcounter = 0

    call JumpTo
    ..msglist:
    rd	 .__info.msgcount
    dd	 0

    .ondefault:
}


macro onmessage message {
  .#message:
  .#message#.__info.id = 3
  .#message#.__info.number = msgcounter / 4
     store word message at (msglist + msgcounter)
     store word ($ - msglist - msgcounter - 4 ) at (msglist + msgcounter + 2)
  msgcounter = msgcounter + 4
}

macro endwp
 {
   .__info.msgcount = msgcounter / 4
   purge ret,locals,endl
   finish@proc
   purge finish@proc
   restore regs@proc
   match all,args@proc \{ restore all \}
   restore args@proc
   match all,all@vars \{ restore all \} }


;*****************************************
; Initialize/Finalize procedures.
;*****************************************


macro initialize procname{
  match any,__init_chain \{ __init_chain equ __init_chain,procname \}
  match ,__init_chain \{ __init_chain equ procname \}
  proc procname
}

macro finalize procname{
  match any,__init_chain \{ __finish_chain equ __finish_chain,procname \}
  match ,__init_chain \{ __finish_chain equ procname \}
  proc procname
}


macro __call_chain [proc] {
if ~proc eq
  call proc
end if
}

macro InitializeAll {
   match list,__init_chain \{ __call_chain list \}
}

macro FinalizeAll {
   match list,__finish_chain \{ __call_chain list \}
}

__init_chain equ
__finish_chain equ


;****************************************
; INT3 break point, when first = second.
;****************************************

macro BreakEq first, second {
  local .lbl
  push	eax
  mov	eax, first
  cmp	eax, second
  pop	eax
  jne	.lbl

  int3

.lbl:
}


macro closeproc {
  open@proc equ
}
closeproc